<?php
/**
 * BaseMail
 * - Send mail and in future, receive mail
 * @author Do Truong Giang
 * $Id: BaseMail.class.php,v 1.1 2009/05/23 10:12:53 quyennt Exp $
 */
class BaseMail {
	/**
	 * Constructor
	 */
	public function BaseMail() {
	}
	/**
	 * sendMail
	 * - Send a mail to a specified address
	 * - Mail has to be converted to JIS to send Japanese
	 * - This function convert UTF-8 to SJIS since the server's code is UTF-8
	 */
	public static function sendMail($fromEmail, $toEmail, $subject, $body) {
		mb_language("ja");
		$internalEncoding = "UTF-8";
		mb_internal_encoding($internalEncoding);
		
		$headers = "MIME-Version: 1.0\n";
		$headers .= "Content-Type: text/plain; charset=iso-2022-jp\n";
		$headers .= "From: $fromEmail";
		
		// convert to JIS
		$subject = mb_convert_encoding( $subject, 'ISO-2022-JP', $internalEncoding);
		$body = str_replace("\r", "\n", str_replace("\r\n", "\n", $body));
		$body = mb_convert_encoding($body, 'ISO-2022-JP', $internalEncoding);
	
		mb_send_mail($toEmail, $subject, $body, $headers);
	}
}
?>